package com.xiaojie.importdata.handler;

import com.xiaojie.importdata.handler.impl.ReplaceAtuoGenerateFieldValue;
import com.xiaojie.importdata.handler.impl.ReplaceFieldValueByParams;
import com.xiaojie.importdata.handler.impl.ReplaceRefFieldValue;
import com.xiaojie.parse.model.Table;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @ClassName ReplaceFieldValueChain
 * @Author wangye
 * @Date 2022/3/13
 **/
@Component
public class ReplaceFieldValueChain {
    //关联字段值修改
    private final static List<ReplaceFieldValueHandler> REF_FIELD_VALUE_HANDLERS;
    //非关联字段值修改
    private final static List<ReplaceFieldValueHandler> FIELD_VALUE_HANDLERS;

    static {
        REF_FIELD_VALUE_HANDLERS = Arrays.asList(new ReplaceRefFieldValue());
        FIELD_VALUE_HANDLERS = Arrays.asList(new ReplaceAtuoGenerateFieldValue(), new ReplaceFieldValueByParams());
    }

    public void replaceFiledValue(String tableName, Table table, Map rowData) {
        for (ReplaceFieldValueHandler handler : FIELD_VALUE_HANDLERS) {
            handler.replaceFieldValue(tableName, table, rowData);
        }
    }

    public void replaceRefFiledValue(String tableName, Table table, Map rowData) {
        for (ReplaceFieldValueHandler handler : REF_FIELD_VALUE_HANDLERS) {
            handler.replaceFieldValue(tableName, table, rowData);
        }
    }


}
